/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef REFCOLLECTION_H
#define REFCOLLECTION_H

#include <vector>
#include <algorithm>

namespace liba
{

class Atom;

/**
 * @stereotype container 
 */
template<typename T>
class RefCollection : public std::vector<T *>
{
	typedef std::vector<T *> base_type;
public:
	T * find(const Atom & name)
	{ 
		iterator it = base_type::begin();
		for( ; it != base_type::end(); ++it )
		{
			if ( (*it)->GetName() == name )
				return *it;
		}
		return NULL;
	}
	void add( T * t )
	{
		base_type::push_back( t );
	}
	void remove( T * t )
	{
		iterator it = std::find( base_type::begin(), base_type::end(), t );
		if ( it != base_type::end() )
			it = base_type::erase( it );
	}

	typedef typename std::vector< T * >::iterator iterator;
};

} // namespace liba
using namespace liba;

#endif //REFCOLLECTION_H